package com.yishu.shop.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * 订单相关服务
 *
 * @author zengchao
 * @date 2021-07-14 20:51:13
 */
@Component
@Slf4j
public class OrderService {

    @HystrixCommand(fallbackMethod = "getOrderInfoFallback",
    commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "3000")
    })
    public Object getOrderInfo(String orderNo){
        int length = orderNo.length();
        try {
            TimeUnit.SECONDS.sleep(length);
        } catch (InterruptedException e) {
            log.error("服务出错!",e);
        }
        return "正常返回订单信息:"+orderNo;
    }


    public Object getOrderInfoFallback(String orderNo){
        return "降级返回订单信息:"+orderNo;
    }
}
